<template>
  <div style="margin-top:30px">
    <el-form ref="form" :rules="rules" :model="form" label-width="80px">
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="账号" prop="phone" style="margin-right:15px">
              <el-input v-model="form.phone" placeholder="账号" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="密码" prop="currentPassword" style="margin-right:15px">
              <el-input v-model="form.currentPassword" placeholder="密码" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="公司名称" prop="title" style="margin-right:15px">
              <el-input v-model="form.name" placeholder="公司名称" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="公司地址" prop="address" style="margin-right:15px">
              <el-input v-model="form.address" placeholder="请输入公司地址" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
      <el-col :span="24">
        <div class="grid-content bg-purple">
          <el-form-item label="高德接口类型" prop="amapType" style="margin-right:15px">
            <el-select v-model="form.amapType" placeholder="请选择" clearable>
                <el-option v-for="item in amapTypeOptions" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
          </el-form-item>
        </div>
      </el-col>
    </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="400客服" prop="branchPhone" style="margin-right:15px">
              <el-input v-model="form.branchPhone" placeholder="400客服" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <!-- 如果是超级管理员 显示以下   如果是平台用户  不显示以下 -->
      <el-row v-show="isSuperShow">
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="司机AppKey" prop="driverAppkey" style="margin-right:15px">
              <el-input v-model="form.driverAppkey" placeholder="司机AppKey" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row   v-show="isSuperShow">
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="司机Secret" prop="driverSecret" style="margin-right:15px">
              <el-input v-model="form.driverSecret" placeholder="司机Secret" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24"   v-show="isSuperShow">
          <div class="grid-content bg-purple">
            <el-form-item label="入驻商AppKey" prop="shipperAppkey" style="margin-right:15px">
              <el-input v-model="form.shipperAppkey" placeholder="入驻商AppKey" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row   v-show="isSuperShow">
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="入驻商Secret" prop="shipperSecret" style="margin-right:15px">
              <el-input v-model="form.shipperSecret" placeholder="入驻商Secret" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <!-- 到这里 -->


      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="推送模式" prop="pushModel" style="margin-right:15px">
             <el-select v-model="form.pushModel" placeholder="请选择" clearable>
                  <el-option v-for="item in pushModelOptions" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
            </el-form-item>
          </div>
        </el-col>
      </el-row>
       <el-row>
              <el-col :span="24">
                <div class="grid-content bg-purple">
                  <el-form-item label="可编辑类型" prop="editType" style="margin-right:15px">
                    <el-select v-model="form.editType" placeholder="请选择" clearable>
                      <el-option  v-for="item in editTypeOptions" :key="item.value" :label="item.label" :value="item.value" />
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>
            </el-row>
     <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="软件版本" prop="softVersion" style="margin-right:15px">
              <el-select v-model="form.softVersion" placeholder="请选择" clearable v-if="partyType == 'SUPER_ADMIN'">
                <el-option   v-for="item in softVersionOptions0" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
              <el-select v-model="form.softVersion" placeholder="请选择" clearable  v-else>
                <el-option v-for="item1 in  softVersionOptions1" :key="item1.value" :label="item1.label" :value="item1.value" />
              </el-select>
            </el-form-item>
          </div>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="funcCancel">取 消</el-button>
      <el-button type="primary" @click="funcSubmit">确 定</el-button>
    </div>
  </div>
</template>
<script>
import Vue from 'vue'
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'
import request from '@/utils/request'
import { isURL } from '@/utils/validate4Form'
Vue.use(VXETable)
export default {
  name: 'PartnerShipsAdd',
  data() {
    return {
      form: {
        phone: '',
        currentPassword: '',
        name: '',
        address: '',
       amapType: '',
        branchPhone: '',
        pushModel: '',
        softVersion: ''
      },
      // 软件版本-- 超级管理员
      softVersionOptions0: [
          { label: '高级版', value: 'high'},
          { label: '总部版', value: 'head'},
          { label: '基础版', value: 'basic'}
      ],
      //软件版本--平台用户
      softVersionOptions1: [
          { label: '基础版', value: 'basic'}
      ],
     // 推送模式(0:派单模式,1:抢单模式,2:混合模式)
      pushModelOptions: [
          { label: '派单模式', value: '0'},
          { label: '抢单模式', value: '1'},
          { label: '混合模式', value: '2'}
      ],
      // 可编辑类型(custom 客户，platform 中台)
      editTypeOptions: [
          { label: '客户', value: 'custom'},
          { label: '中台', value: 'platform'}
      ],
      // 高德地图接口类型(0:小车,1:货车)
      amapTypeOptions: [
          { label: '小车', value: '0'},
          { label: '货车', value: '1'}
      ],
      rules: {
        phone: [
          { required: true, message: '请输入登陆账号', trigger: 'blur' }
        ]
      },
      branchDetail:{
      },
      isSuperShow: false,
      partyType: '', // 用户类型
    }
    },
  created() {
    this.demo()
  },
  methods: {
    // 提交
    funcSubmit() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          const data = this.form
          request({ url: '/arpa-basic-api/partyGroup/addBranch', method: 'post', params: data }).then(response => {
            this.$message({ message: response.msg, type: 'success' })
            this.$emit('fatherAddMethod')
          }).then(() => this.$refs['form'].resetFields())
        } else {
          return false
        }
      })
    },
    demo(){
      request({ url: '/arpa-basic-api/party/one', method: 'get' }).then(response => {
                  this.branchDetail = response.data.msg
                  this.$message({ message: response.msg, type: 'success' })
                  this.$emit('fatherAddMethod')
                  this.partyType = response.data.partyType
                  if (response.data.partyType == 'SUPER_ADMIN') {
                    this.isSuperShow = true
                  } else {
                    this.isSuperShow = false
                  }
                })
    },
    // 取消
    funcCancel() {
      this.$emit('fatherCancelMethod', 'add')
    }
  }
}
</script>
<style lang="scss" scoped>
  .dialog-footer {
    margin: 15px 0 15px 0;
    width: 175px;
    float: right;
  }
</style>
